<template>
	<div>
		<vxe-modal
			v-model="show" id="admin_statisicadd" width="60%" height="80vh" :size="size" :position="{top: '10%'}"
			@close="closeForm()" @show="open" show-zoom resize transfer show-footer destroy-on-close>
			<!-- storage 将窗口拖动的状态保存到本地 remember 再次打开窗口时还原窗口状态-->
			<!--标题-->
			<template #title>
				<span style="font-weight: bold;">添加</span>
			</template>
			<!--主体-->
			<template #default>
				<el-form :size="size" ref="form" :model="form" class="form" :rules="rules" label-width="120px">
					<!-- 标题 -->
					<el-row >
						<el-col :span="24">
							<el-form-item  prop="name">
								<template slot="label">
									<span>标题 </span>
								</template>
								<el-input tabindex="1"  v-model="form.name" autoComplete="off" clearable  placeholder="请输入标题">
								</el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<!-- 类型 -->
					<el-row >
						<el-col :span="24">
							<el-form-item  prop="type">
								<template slot="label">
									<span>类型 </span>
								</template>
								<el-radio-group v-model="form.type">
									<el-radio :label="parseInt(1)">值</el-radio>
									<el-radio :label="parseInt(2)">SQL</el-radio>
								</el-radio-group>
							</el-form-item>
						</el-col>
					</el-row>
					<!-- 值 -->
					<el-row >
						<el-col :span="24">
							<el-form-item  prop="value">
								<template slot="label">
									<span>值 </span>
								</template>
								<el-input tabindex="5"  type="textarea" autoComplete="off" v-model="form.value"  :autosize="{ minRows: 2, maxRows: 4}" clearable placeholder="请输入值"/>
							</el-form-item>
						</el-col>
					</el-row>
					<!-- 排序 -->
					<el-row >
						<el-col :span="24">
							<el-form-item  prop="sort_id">
								<template slot="label">
									<span>排序 </span>
								</template>
								<el-input-number controls-position="right" style="width:200px;" autoComplete="off" v-model="form.sort_id" clearable :min="0" placeholder="排序"/>
							</el-form-item>
						</el-col>
					</el-row>
					<!-- 状态 -->
					<el-row >
						<el-col :span="24">
							<el-form-item  prop="status">
								<template slot="label">
									<span>状态 </span>
								</template>
								<el-switch :active-value="1" :inactive-value="0" v-model="form.status"></el-switch>
							</el-form-item>
						</el-col>
					</el-row>
					<!-- 创建时间 -->
				</el-form>
			</template>
			<!--底部-->
			<template #footer>
				<el-button :size="size" :loading="loading" type="primary" @click="submit">
					<span v-if="!loading">确 定</span><span v-else>提 交 中...</span>
				</el-button>
				<el-button :size="size" @click="closeForm">取 消</el-button>
			</template>
		</vxe-modal>
	</div>
</template>
<script>
import { add  } from '@/api/admin/admin/statisic'
import mixinVexTable from "@/mixin/vxeTable"
export default {
	name:'admin_statisicadd',
	mixins: [mixinVexTable],
	components: {
	},
	props: {
		show: {
			type: Boolean,
			default: false
		},
		size: {
			type: String,
			default: 'small'
		},
	},
	data(){
		return {
			form: {
				name:'',
				type:1,
				value:'',
				status:1,
				create_time:'',
			},
			loading:false,
			rules: {
			},
		}
	},
	methods: {
		open(){
		},
		submit(){
			this.$refs['form'].validate(valid => {
				if(valid) {
					this.loading = true
					add(this.form).then(res => {
						if(res.status == 200){
							this.$message({message: '操作成功', type: 'success'})
							this.$emit('refesh_list')
							this.closeForm()
						}
					}).catch(()=>{
						this.loading = false
					})
				}
			})
		},
		closeForm(){
			this.$emit('update:show', false)
			this.loading = false
			if (this.$refs['form']!==undefined) {
				this.$refs['form'].resetFields()
			}
		},
	}
}
</script>
<style scoped lang="scss">
@import '@/assets/scss/common.scss'
</style>
